//
//  FocusDoctorController.m
//  QuickCure1
//
//  Created by maoge on 16/10/30.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "FocusDoctorController.h"
#import "NetWorkManager.h"
#import "YJDoctorsIfonModel.h"
#import "YJCareDoctorsViewCell.h"
#import "YJDoctorDetailInfoController.h"
#import <MJRefresh.h>


static NSString *cellId = @"cellId";
@interface FocusDoctorController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak) UITableView *doctorsInfoTableView;

@property (nonatomic, strong) NSArray<YJDoctorsIfonModel *> *modelList;

@end

@implementation FocusDoctorController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"选择医生";
    
    [self setupUI];
    
}

#pragma mark - 搭建UI,设置界面
- (void)setupUI
{
    [self getData];
    
    //布局tableView
    [self setupTableView];
    
    
    
}

#pragma mark -
#pragma mark - 获取数据
- (void)getData
{
    
    [YJDoctorsIfonModel getDoctorsIfonModellistComplete:^(NSArray<YJDoctorsIfonModel *> *modelList) {
        
        self.modelList = modelList;
        [self.doctorsInfoTableView reloadData];
        [self.doctorsInfoTableView.mj_header endRefreshing];
        
    }];
}


#pragma mark -
#pragma mark - 布局tableView
- (void)setupTableView
{
    UITableView *doctorsInfoTableView = [[UITableView alloc] init];
    
    self.doctorsInfoTableView = doctorsInfoTableView;
    
    [self.view addSubview:doctorsInfoTableView];
    
    [doctorsInfoTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.view);
    }];
    
    [self.doctorsInfoTableView registerNib:[UINib nibWithNibName:@"YJCareDoctorsViewCell" bundle:nil] forCellReuseIdentifier:cellId];
    
    self.doctorsInfoTableView.dataSource = self;
    self.doctorsInfoTableView.delegate = self;
    
    self.doctorsInfoTableView.rowHeight = 100;
    
    self.doctorsInfoTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self getData];
    }];
    
    
    

}

#pragma mark -
#pragma mark - tableView数据源方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YJDoctorsIfonModel *model = self.modelList[indexPath.row];
    
    YJCareDoctorsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    
    cell.model = model;

    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.modelList.count;
}

#pragma mark -
#pragma mark - tableView代理方法

/**
 选中cell的委托方法
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    YJDoctorsIfonModel *model = self.modelList[indexPath.row];
    
    YJDoctorDetailInfoController *vc = [[YJDoctorDetailInfoController alloc] init];
    
    vc.model = model;
    
    [self.navigationController pushViewController:vc animated:YES];
}


@end
